package java类及封装;
// TestStudent2.java
public class b {
    public static void main(String[] args) {
        b stu = new b();
        stu.setStudentId("20250803");
        stu.setName("王五");
        stu.setAge(20);
        stu.setAge(15);

        System.out.println("学生信息：" + stu.getStudentId() + " " + stu.getName() + " " + stu.getAge() + "岁");
    }

    private String studentId;
    private String name;
    private int age;

    public String getStudentId() {
        return studentId;
    }

    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age >= 18 && age <= 30) {
            this.age = age;
        } else {
            System.out.println("年龄不合法（必须18-30岁）");
        }
    }
}
